********Tables H.1 and H.2 - Indonesia ********

*Load data and create differences
cd "$reploc/data/created_data"
use indo_full, clear

sort pidlink ifls
drop if ifls==.
keep if panel==1

*Normalize monetary variables
gen assets_ia_use=assets_ia/1000000
gen income_ia_use=income_ia/1000000
gen savingnettotal_ia_use=savingnettotal_ia/1000000
gen liquidassets_ia_use=liquidassets_ia/1000000
gen nonliquidassets_ia_use=nonliquidassets_ia/1000000
gen homelandassets_ia_use=homelandassets_ia/1000000
gen nonhomelandassets_ia_use=nonhomelandassets_ia/1000000
gen laborincome_ia_use=laborincome_ia/1000000
gen nonlaborincome_ia_use=nonlaborincome_ia/1000000
rename nonhomelandassets_ia_use nonhlassets_ia_use

*Generate higher order + quintiles
foreach var of varlist assets_ia_use income_ia_use savingnettotal_ia_use nonliquidassets_ia_use liquidassets_ia_use homelandassets_ia_use nonhlassets_ia_use laborincome_ia_use nonlaborincome_ia_use {

xtile `var'decifls4=`var' if ifls==4, nq(5)
xtile `var'decifls5=`var' if ifls==5, nq(5)

gen `var'dec=`var'decifls4 if ifls==4
replace `var'dec=`var'decifls5 if ifls==5


tab `var'dec, gen(`var'decdum)

forval i=2/4 {

gen `var'term`i'=(`var')^`i'

}
}


keep rbuc* gambleaverse ifls pidlink inflation imp_age panel biryear_impl grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? married hhsize hhsize_sq Eddum* birprov_impl income_ia_use assets_ia_use savingnettotal_ia_use safe_village walk_village civil_strife_hh civil_strifebad_hh dis_*_hh disbad_*_hh assets_ia_useterm2 assets_ia_useterm3 assets_ia_useterm4 income_ia_useterm2 income_ia_useterm3 income_ia_useterm4 nonliquidassets_ia_use nonliquidassets_ia_useterm2 nonliquidassets_ia_useterm3 nonliquidassets_ia_useterm4 liquidassets_ia_use liquidassets_ia_useterm2 liquidassets_ia_useterm3 liquidassets_ia_useterm4 homelandassets_ia_use nonhlassets_ia_use homelandassets_ia_useterm2 nonhlassets_ia_useterm2 homelandassets_ia_useterm3 nonhlassets_ia_useterm3 homelandassets_ia_useterm4 nonhlassets_ia_useterm4 laborincome_ia_use nonlaborincome_ia_use laborincome_ia_useterm2 nonlaborincome_ia_useterm2 laborincome_ia_useterm3 nonlaborincome_ia_useterm3 laborincome_ia_useterm4 nonlaborincome_ia_useterm4 income_ia_usedecdum* assets_ia_usedecdum*

reshape wide rbuc* gambleaverse inflation imp_age panel grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? married hhsize hhsize_sq Eddum* income_ia_use assets_ia_use savingnettotal_ia_use safe_village walk_village civil_strife_hh civil_strifebad_hh dis_*_hh disbad_*_hh assets_ia_useterm2 assets_ia_useterm3 assets_ia_useterm4 income_ia_useterm2 income_ia_useterm3 income_ia_useterm4 nonliquidassets_ia_use nonliquidassets_ia_useterm2 nonliquidassets_ia_useterm3 nonliquidassets_ia_useterm4 liquidassets_ia_use liquidassets_ia_useterm2 liquidassets_ia_useterm3 liquidassets_ia_useterm4 homelandassets_ia_use nonhlassets_ia_use homelandassets_ia_useterm2 nonhlassets_ia_useterm2 homelandassets_ia_useterm3 nonhlassets_ia_useterm3 homelandassets_ia_useterm4 nonhlassets_ia_useterm4 laborincome_ia_use nonlaborincome_ia_use laborincome_ia_useterm2 nonlaborincome_ia_useterm2 laborincome_ia_useterm3 nonlaborincome_ia_useterm3 laborincome_ia_useterm4 nonlaborincome_ia_useterm4 assets_ia_usedecdum1 assets_ia_usedecdum2 assets_ia_usedecdum3 assets_ia_usedecdum4 assets_ia_usedecdum5 income_ia_usedecdum1 income_ia_usedecdum2 income_ia_usedecdum3 income_ia_usedecdum4 income_ia_usedecdum5, i(pidlink) j(ifls)


local varlist1 rbuc rbucB rbuc_nga rbuc_garefined rbucgaref1a rbucgaref2a rbucgaref3a rbucgaref4a gambleaverse inflation imp_age panel grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co2 grbrprovSD_lam0co2 grbrprovAvg_lam0co3 grbrprovSD_lam0co3 married hhsize hhsize_sq income_ia_use assets_ia_use savingnettotal_ia_use safe_village walk_village civil_strife_hh civil_strifebad_hh assets_ia_useterm2 assets_ia_useterm3 assets_ia_useterm4 income_ia_useterm2 income_ia_useterm3 income_ia_useterm4 nonliquidassets_ia_use nonliquidassets_ia_useterm2 nonliquidassets_ia_useterm3 nonliquidassets_ia_useterm4 liquidassets_ia_use liquidassets_ia_useterm2 liquidassets_ia_useterm3 liquidassets_ia_useterm4 homelandassets_ia_use nonhlassets_ia_use homelandassets_ia_useterm2 nonhlassets_ia_useterm2 homelandassets_ia_useterm3 nonhlassets_ia_useterm3 homelandassets_ia_useterm4 nonhlassets_ia_useterm4 laborincome_ia_use nonlaborincome_ia_use laborincome_ia_useterm2 nonlaborincome_ia_useterm2 laborincome_ia_useterm3 nonlaborincome_ia_useterm3 laborincome_ia_useterm4 nonlaborincome_ia_useterm4 assets_ia_usedecdum1 assets_ia_usedecdum2 assets_ia_usedecdum3 assets_ia_usedecdum4 assets_ia_usedecdum5 income_ia_usedecdum1 income_ia_usedecdum2 income_ia_usedecdum3 income_ia_usedecdum4 income_ia_usedecdum5


foreach var in `varlist1'  {
gen `var'dif=.
replace `var'dif=`var'5-`var'4
}


foreach var of varlist Eddum*5 dis_*_hh5 disbad_*_hh5 {

local im=substr("`var'",1,length("`var'")-1)

gen `im'dif=.
replace `im'dif=`var'-`im'4

}
 
*Generate cohort by birthyear variables to cluster on
egen coh_prov_clust=group(biryear_impl birprov_impl)

*Table H.1 - Regressions
local x rbuc_garefined
local rhsvari oldindoonly
local rhsvaruse _lam0co3dif
local usei grbr
local macrouse `usei'provAvg`rhsvaruse' `usei'provSD`rhsvaruse'

cd "$reploc/results"

*Column 1
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif, vce(cluster coh_prov_clust)
outreg2 using TableH1_Indonesia.tex, replace label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)
				
*Column 2
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif assets_ia_useterm?dif , vce(cluster coh_prov_clust)
outreg2 using TableH1_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)	
		
*Column 3
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif assets_ia_usedecdum*dif , vce(cluster coh_prov_clust)		
outreg2 using TableH1_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)	

*Column 4
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif liquidassets_ia_usedif nonliquidassets_ia_usedif, vce(cluster coh_prov_clust)
outreg2 using TableH1_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)	

*Column 5
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif liquidassets_ia_usedif nonliquidassets_ia_usedif liquidassets_ia_useterm?dif nonliquidassets_ia_useterm?dif , vce(cluster coh_prov_clust)
outreg2 using TableH1_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)	

*Column 6 
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif homelandassets_ia_usedif nonhlassets_ia_usedif, vce(cluster coh_prov_clust)
outreg2 using TableH1_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)	

*Column 7
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif homelandassets_ia_usedif nonhlassets_ia_usedif homelandassets_ia_useterm?dif nonhlassets_ia_useterm?dif , vce(cluster coh_prov_clust)
outreg2 using TableH1_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)


*Table H.2 - Regressions

local x rbuc_garefined
local rhsvari oldindoonly
local rhsvaruse _lam0co3dif
local usei grbr
local macrouse `usei'provAvg`rhsvaruse' `usei'provSD`rhsvaruse'

cd "$reploc/results"

*Column 1
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif, vce(cluster coh_prov_clust)
outreg2 using TableH2_Indonesia.tex, replace label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 2
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif income_ia_useterm?dif , vce(cluster coh_prov_clust)
outreg2 using TableH2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 3
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif income_ia_usedecdum*dif , vce(cluster coh_prov_clust)
outreg2 using TableH2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 4
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif laborincome_ia_usedif nonlaborincome_ia_usedif, vce(cluster coh_prov_clust)
outreg2 using TableH2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 5
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif safe_villagedif walk_villagedif civil_strife_hhdif civil_strifebad_hhdif dis_*_hhdif disbad_*_hhdif laborincome_ia_usedif nonlaborincome_ia_usedif laborincome_ia_useterm?dif nonlaborincome_ia_useterm?dif , vce(cluster coh_prov_clust)
outreg2 using TableH2_Indonesia.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

	
